package com.campus.service.impl;

import com.campus.dao.*;
import com.campus.dao.impl.TeacherDaoImpl;
import com.campus.dto.*;
import com.campus.model.*;
import com.campus.model.Class;
import com.campus.service.ManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ManagerServiceImpl implements ManagerService {
    @Autowired
    TeacherDao teacherDao;
    @Autowired
    UserDao userDao;
    @Autowired
    ActivityDao activityDao;
    @Autowired
    ClassDao classDao;
    @Autowired
    StudentDao studentDao;
    @Override
    public Integer addTeacher(TeacherDto teacherDto) {
        Teacher teacher = new Teacher();
        teacher.setTeacher_id(teacherDto.getTeacher_id());
        teacher.setName(teacherDto.getName());
        teacher.setSubject(teacherDto.getSubject());
        teacher.setProfession(teacherDto.getProfession());
        teacher.setSchool(teacherDto.getSchool());
        teacher.setIntroduce(teacherDto.getIntroduce());
        teacher.setLogin_id(teacherDto.getLogin_id());
        return teacherDao.addTeacher(teacher);
    }
    @Override
    public Teacher queryTeacherById(int teacherId) {
        return teacherDao.queryTeacherById(teacherId);
    }

    @Override
    public List<Teacher> queryTeacherByName(String name) {
        return teacherDao.queryTeacherByName(name);
    }

    @Override
    public Integer addActivity(ActivityDto activityDto) {
        Activity activity = new Activity();
        activity.setName(activityDto.getName());
        activity.setCategory(activityDto.getCategory());
        activity.setTitle(activityDto.getTitle());
        activity.setCreator(activityDto.getCreator());
        activity.setActivity_abstract(activityDto.getActivity_abstract());
        activity.setDetailed_desc(activityDto.getDetailed_desc());
        activity.setStatus(0);
        activity.setCreated_time(activityDto.getCreated_time());
        activity.setPic_urls(activityDto.getPic_urls());
        return activityDao.addActivity(activity);
    }

    @Override
    public Integer editActivity(ActivityDto newactivityDto) {
        Activity newactivity = new Activity();
        newactivity.setActivity_id(newactivityDto.getActivity_id());
        newactivity.setName(newactivityDto.getName());
        newactivity.setCategory(newactivityDto.getCategory());
        newactivity.setTitle(newactivityDto.getTitle());
        newactivity.setCreator(newactivityDto.getCreator());
        newactivity.setActivity_abstract(newactivityDto.getActivity_abstract());
        newactivity.setDetailed_desc(newactivityDto.getDetailed_desc());
        newactivity.setStatus(0);
        newactivity.setCreated_time(newactivityDto.getCreated_time());
        newactivity.setPic_urls(newactivityDto.getPic_urls());
        return activityDao.editActivity(newactivity);
    }

    @Override
    public Integer publishActivity(int activityId) {
        return activityDao.publishActivity(activityId);
    }

    @Override
    public List<Activity> queryActivityByStatus(int status) {
        return activityDao.queryActivityByStatus(status);
    }

    @Override
    public List<Activity> queryActivityByName(String name) {
        return activityDao.queryActivityByName(name);
    }

    @Override
    public Integer addClass(ClassDto classDto) {
        Class camp_class = new Class();
        camp_class.setClass_id(classDto.getClass_id());
        camp_class.setName(classDto.getName());
        camp_class.setCreated_time(classDto.getCreated_time());
        camp_class.setClass_desc(classDto.getClass_desc());
        camp_class.setActivity_id(classDto.getActivity_id());
        camp_class.setTeacher_id(classDto.getTeacher_id());
        return classDao.addClass(camp_class);
    }

    @Override
    public Integer modifyClass(ClassDto newclassDto) {
        Class newclass = new Class();
        newclass.setClass_id(newclassDto.getClass_id());
        newclass.setName(newclassDto.getName());
        newclass.setCreated_time(newclassDto.getCreated_time());
        newclass.setClass_desc(newclassDto.getClass_desc());
        newclass.setActivity_id(newclassDto.getActivity_id());
        newclass.setTeacher_id(newclassDto.getTeacher_id());
        return classDao.modifyClass(newclass);
    }
    @Override
    public Integer allocateTeacher(int class_id,int teacher_id) {
        return classDao.allocateTeacher(class_id,teacher_id);
    }

    @Override
    public Integer addStudentsToClass(int classId, List<Integer> studentIds) {
        return classDao.addStudentsToClass(classId,studentIds);
    }

    @Override
    public Integer addStudent(StudentDto studentDto) {
        Student student = new Student();
        student.setStudent_id(studentDto.getStudent_id());
        student.setStu_name(studentDto.getStu_name());
        student.setFrom_place(studentDto.getFrom_place());
        student.setParent_phone(studentDto.getParent_phone());
        student.setCurrent_grade(studentDto.getCurrent_grade());
        student.setIs_first(studentDto.getIs_first());
        student.setLogin_id(studentDto.getLogin_id());
        student.setComment(studentDto.getComment());
        return studentDao.addStudent(student);
    }

    @Override
    public Integer addStudentByExcel(String excelPath) {
        return studentDao.addStudentByExcel(excelPath);
    }

    @Override
    public Integer auditStudent(int studentId) {
        return studentDao.auditStudent(studentId);
    }

    @Override
    public Integer batchAuditStudent() {
        return studentDao.batchAuditStudent();
    }

    @Override
    public Integer addUser(UserDto userDto) {
        User user = new User();
        user.setUser_id(userDto.getUser_id());
        user.setName(userDto.getName());
        user.setPassword(userDto.getPassword());
        user.setGender(userDto.getGender());
        user.setPhone(userDto.getPhone());
        user.setBirthday(userDto.getBirthday());
        user.setEmail(userDto.getEmail());
        user.setStatus(userDto.getStatus());
        return userDao.insert(user);
    }
    @Override
    public List<User> queryUserByName(String name) {
        return userDao.queryUserByName(name);
    }




}
